//
//  JLMainHomeViewController.m
//  JLStyleApp
//
//  Created by LvJianfeng on 15/10/10.
//  Copyright © 2015年 JLStyle. All rights reserved.
//

#import "JLMainHomeViewController.h"
#import "JLShowPersonMsgViewController.h"
#import "JLEditModuleListTableViewController.h"

@interface JLMainHomeViewController ()
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIButton *showResume;
@property (nonatomic, strong) UIButton *editResume;
@property (nonatomic, strong) UIButton *other;
@end

@implementation JLMainHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.topView];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
//    [UIView animateWithDuration:5.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//        self.editResume.alpha = 1;
//        self.editResume.frame = CGRectMake(90, 310, 100, 100);
//    } completion:nil];
    
    [self.view addSubview:self.showResume];
    [self.view addSubview:self.editResume];
}


- (void)showResumeAction:(UIButton *)sender{
    CATransition *transition = [CATransition animation];
    transition.duration = 3.0f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = @"rippleEffect";
    transition.subtype = kCATransitionFromRight;
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    
    JLShowPersonMsgViewController *showresume = [[JLShowPersonMsgViewController alloc] init];
    [self.navigationController pushViewController:showresume animated:YES];
}

- (void)editResumeAction:(UIButton *)sender{
//    CATransition *transition = [CATransition animation];
//    transition.duration = 1.0f;
//    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//    transition.type = @"cube";
//    transition.subtype = kCATransitionFromRight;
//    transition.delegate = self;
//    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    
    JLEditModuleListTableViewController *editModuleListVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:NSStringFromClass([JLEditModuleListTableViewController class])];
    [self.navigationController pushViewController:editModuleListVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark lazyload
- (UIView *)topView{
    if (_topView==nil) {
        UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 200)];
        topView.backgroundColor = GlobalColor;
        _topView = topView;
    }
    return _topView;
}

- (UIButton *)showResume{
    if (_showResume==nil) {
        _showResume = [UIButton buttonWithType:UIButtonTypeCustom];
        _showResume.frame = CGRectMake(-200, 260, 200, 200);
        _showResume.layer.cornerRadius = 100;
        _showResume.layer.borderWidth = 1;
        _showResume.layer.borderColor = [UIColor grayColor].CGColor;
        [_showResume setTitle:@"Edit" forState:UIControlStateNormal];
        [_showResume setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [_showResume addTarget:self action:@selector(showResumeAction:) forControlEvents:UIControlEventTouchUpInside];

        POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
        anim.fromValue = @(0.0);
        anim.toValue = @(1.0);
        anim.duration = 2;
        [_showResume pop_addAnimation:anim forKey:@"fade"];
        
        POPDecayAnimation *anDecay = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];
        anDecay.velocity = @(ScreenWidth/2+200+200);
        anDecay.beginTime = CACurrentMediaTime() + 1.0f;
        [_showResume pop_addAnimation:anDecay forKey:@"position"];
        
    }
    return _showResume;
}

- (UIButton *)editResume{
    if (_editResume==nil) {
        _editResume = [UIButton buttonWithType:UIButtonTypeCustom];
        _editResume.frame = CGRectMake(15, ScreenHeight, 180, 60);
        _editResume.layer.cornerRadius = 30;
        _editResume.layer.borderWidth = 1;
        _editResume.layer.borderColor = GlobalColor.CGColor;
        [_editResume setTitle:@"Edit" forState:UIControlStateNormal];
        [_editResume setTitleColor:GlobalColor forState:UIControlStateNormal];
        [_editResume addTarget:self action:@selector(editResumeAction:) forControlEvents:UIControlEventTouchUpInside];
        
        POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
        anim.fromValue = @(0.0);
        anim.toValue = @(1.0);
        anim.duration = 3;
        [_editResume pop_addAnimation:anim forKey:@"fade"];
        
        POPDecayAnimation *anDecay = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionY];
        anDecay.velocity = @(-200);
        anDecay.beginTime = CACurrentMediaTime() + 1.0f;
        [_editResume pop_addAnimation:anDecay forKey:@"position"];
    }
    return _editResume;
}
@end
